namespace ScrumSprintMonitor.Samples.Feed.RSS
{
	#region #using Directives

	using System.ComponentModel;
	using System.IO;
	using System.Xml.Serialization;

	#endregion

	[XmlRoot(ElementName = "rss")]
	public class Rss
	{
		public Rss()
		{
			channel = new Channel {
			                      	items = new BindingList<Item>()
			                      };
		}

		public Rss(string version)
			: this()
		{
			Version = version;
		}

// ReSharper disable InconsistentNaming
		public Channel channel { get; set; }
// ReSharper restore InconsistentNaming

		[XmlAttribute("version")]
		public string Version { get; set; }

		public void Save(string filename)
		{
			var serializer = new XmlSerializer(typeof(Rss));
			using (var stream = File.Create(filename))
			{
				serializer.Serialize(stream, this);
			}
		}

		public static Rss Load(string filename)
		{
			using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
			{
				return Load(stream);
			}
		}

		public static Rss Load(Stream fileStream)
		{
			var serializer = new XmlSerializer(typeof(Rss));
			var ret = (Rss) serializer.Deserialize(fileStream);
			return ret;
		}
	}
}